from sqlalchemy import Column, Integer, String, Boolean, DateTime
from sqlalchemy.sql import func
from backend.config.database import Base


class UserInfo(Base):
    """用户表 - 增强版"""
    __tablename__ = "user_info"
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    username = Column(String(32), unique=True, nullable=False, comment='用户名')
    password_hash = Column(String(255), nullable=False, comment='密码哈希')
    role = Column(String(16), nullable=False, default='user', comment='角色(admin/user)')
    email = Column(String(64), unique=True, nullable=True, comment='邮箱')
    status = Column(Boolean, default=True, comment='状态(1:启用,0:禁用)')
    last_login = Column(DateTime, nullable=True, comment='最后登录时间')
    created_at = Column(DateTime, default=func.now(), comment='注册时间')
    updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment='更新时间')
    
    class Config:
        from_attributes = True